# -*- coding: utf-8 -*-
"""
__mktime__ = '2019/4/15'
__author__ = 'Just'
__filename__ = 'manhua'
"""
from datetime import datetime
from app.model.base import MixinJSONSerializer


class ComicDetailViewModel(MixinJSONSerializer):
    """漫画详细信息"""
    def __init__(self, comic, updates):
        self.cid = comic.cid
        self.title = comic.title
        self.author = comic.author
        self.category = comic.category
        self.area = comic.area
        self.state = updates.state
        self.description = comic.description
        self.image = comic.image
        self.section = updates.latest
        self.update_time = datetime.fromtimestamp(updates.update_time)

        self._fields = ['update_time', 'cid', 'title', 'author', 'category',
                        'area', 'state', 'description', 'image', 'section']


class ComicDetailCollection(MixinJSONSerializer):
    """一组详细信息的漫画列表"""
    def __init__(self):
        self.comics = []
        self.total = None
        self._fields = ['comics', 'total']

    def fill(self, collection):
        """一组"""
        self.comics = [ComicDetailViewModel(item[0], item[1]) for item in collection]
        self.comics.reverse()
        self.total = len(self.comics)
